package com.alex;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import java.math.BigDecimal;
import java.sql.SQLOutput;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * Created by gao.jun on 2015/11/18.
 */
public class Idea {

    private String id;

    private int age;

    public Idea(String id, int age) {
        this.id = id;
        this.age = age;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

//    public static void main(String[] args) {
//        boolean b = "a".equals("d");
//        if (b) {
//            System.out.println("ddd");
//        }
//    }

    public static void main(String[] args) {
//        System.out.println(Math.random());
//        System.out.println((int)(Math.random()*10));
//        System.out.println(new BigDecimal(1.4).divide(new BigDecimal(1), 0, BigDecimal.ROUND_UP));
//        System.out.println(new BigDecimal(1.5).divide(new BigDecimal(1), 0, BigDecimal.ROUND_UP));
//        System.out.println(new BigDecimal(1.6).divide(new BigDecimal(1), 0, BigDecimal.ROUND_UP));

//        System.out.println(2416605%1000);
//        System.out.println(1027696%1000);

//        Lists.newArrayList(123,23, 102, 22).stream()
//                .collect(Collectors.groupingBy(i -> i%10, Collectors.toList()))
//                .forEach((i,l) -> System.out.println(i + ":" + l));

//        List<Integer> hotelIdList = Lists.newArrayList();
//        hotelIdList.addAll(Sets.newHashSet(1,2,3));
//        System.out.println(hotelIdList);

//        Lists.newArrayList(1,2,3,4).forEach( i -> {
//            if (i % 2 == 0) {
//                return;
//            }
//            System.out.println(i);
//        });
//        JSONObject jsonObject = JSONObject.parseObject("{\"key1\":\"123\",\"key2\":{\"key21\":\"val21\",\"key22\":\"val22\"}}");
//        JSONObject jobj1 = jsonObject.getJSONObject("key2");
//        jobj1.remove("key21");
//        System.out.println(jsonObject.toJSONString());

//        int i = 1 == 2 ? 1 : 2 == 3 ? 2 : 3;
//        System.out.println(i == 3);

//        Map<String, String> map = Maps.newHashMap();
//        map.put("k1","v1");
//        map.put("k2","v2");
//        System.out.println(map.toString());
//            count1();
//        count2();
        System.out.println(new Random().nextInt(10));
    }

    public static void count1(){
        BigDecimal bdSalePrice = new BigDecimal(3399);
        BigDecimal bdCommission = new BigDecimal(290);
        BigDecimal commissionRatio = BigDecimal.valueOf(0.7);

        BigDecimal multiply = bdCommission.multiply(commissionRatio);
        System.out.println("m1:" + multiply);
        BigDecimal bdEstBasePrice = bdSalePrice.subtract(multiply);
        System.out.println(bdEstBasePrice.setScale(0, BigDecimal.ROUND_UP).intValue());
    }

    // 计算等效底价用的佣金折算率
    private static final Double COMMISSION_RATIO = 0.7;
    public static void count2(){
        BigDecimal bdSalePrice = new BigDecimal(3399);
        BigDecimal bdCommission = new BigDecimal(290);
        BigDecimal commissionRatio = new BigDecimal(COMMISSION_RATIO);

        BigDecimal multiply = bdCommission.multiply(commissionRatio);
        System.out.println("m2:" + multiply);
        BigDecimal bdEstBasePrice = bdSalePrice.subtract(multiply);
        System.out.println(bdEstBasePrice.setScale(0, BigDecimal.ROUND_UP).intValue());
    }
}
